package com.bw.dao;

import com.bw.pojo.system.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface MenuMapper extends Mapper<Menu> {

    @Select("SELECT id,name,icon,url,parent_id parentId FROM tb_menu WHERE id in( " +
            "SELECT menu_id FROM tb_resource_menu WHERE resource_id in( " +
            "SELECT resource_id FROM tb_role_resource WHERE role_id in( " +
            "select role_id from tb_admin_role WHERE admin_id in( " +
            "SELECT id from tb_admin WHERE login_name=#{loginName} " +
            ")" +
            ")" +
            ")" +
            ") " +
            "UNION " +
            "SELECT id,name,icon,url,parent_id parentId from tb_menu WHERE id in( " +
            "SELECT parent_id FROM tb_menu WHERE id in( " +
            "SELECT menu_id FROM tb_resource_menu WHERE resource_id in(" +
            "SELECT resource_id FROM tb_role_resource WHERE role_id in(" +
            "select role_id from tb_admin_role WHERE admin_id in(" +
            "SELECT id from tb_admin WHERE login_name=#{loginName} " +
            ")" +
            ")" +
            ")" +
            ")" +
            ") " +
            "UNION " +
            "SELECT id,name,icon,url,parent_id parentId from tb_menu WHERE id in( " +
            "SELECT parent_id from tb_menu WHERE id in( " +
            "SELECT parent_id FROM tb_menu WHERE id in( " +
            "SELECT menu_id FROM tb_resource_menu WHERE resource_id in( " +
            "SELECT resource_id FROM tb_role_resource WHERE role_id in( " +
            "select role_id from tb_admin_role WHERE admin_id in( " +
            "SELECT id from tb_admin WHERE login_name=#{loginName} " +
            ")" +
            ")" +
            ")" +
            ")" +
            ")" +
            ")")
    public List<Menu> getMenus(@Param("loginName")String loginName);
}
